<template>
  <div>
    <div class="header">
      <span>欢迎注册</span>
    </div>
    <van-form validate-first @failed="onFailed" @submit="onSubmit" style="padding:2em;">
      <van-field
        v-model="value1"
        placeholder="用户名"
        :rules="[{ pattern, message: '4到16位（字母，数字，下划线，减号）' }]"
      />
      <van-field
        v-model="value2"
        name="validator"
        placeholder="密码"
        :rules="[{ validator, message: '6到16位（字母，数字，小数点）' }]"
      />
      <!-- 通过 validator 进行异步函数校验 -->
      <div style="margin: 16px">
        <van-button round block type="default" native-type="submit" color="rgb(74,218,254)"
          >注册</van-button
        >
      </div>
    </van-form>
    <router-link to="/login" class="toregister">已有账号？去登陆</router-link>
  </div>
</template>

<script>
export default {
  name:"Register",
  data() {
    return {
      value1: "",
      value2: "",
      pattern: /^[a-zA-Z0-9_-]{4,16}$/,
    };
  },
  methods: {
    onFailed(errorInfo) {
      if (errorInfo) {
        console.log("错了");
      }
    },
    validator(val) {
      return /^[a-zA-Z0-9.]{6,16}$/.test(val);
    },
    onSubmit() {
      //带个用户名过去 如果本地有的话就是以登录
    },
  },
};
</script>

<style scoped>
.header span{
  display: inline-block;
  font-size:1.5em;
  font-weight: 200;
  padding: 2em 2em 0 2em;
}
.toregister{
  padding:2em 4em 2em 0;
  float: right;
  text-decoration: underline;
}
</style>